/*================================================================
*   Copyright (C) 2022 Sangfor Ltd. All rights reserved.
*   
*   文件名称：oj_view.hpp
*   创 建 者：wudu
*   创建日期：2022年04月25日
*   描    述：
*
================================================================*/
#pragma once
#include <jsoncpp/json/json.h>
#include <ctemplate/template.h>
#include "oj_model.hpp"

class OjView{
    public:
        static void DrawAllQuestionHtml(vector<Question>& vec, string* html){
            //1.组织ctemplate字典
            ctemplate::TemplateDictionary dict("all_question");

            for(const auto& kv : vec){
                ctemplate::TemplateDictionary* sub_dict = dict.AddSectionDictionary("question");

                sub_dict->SetValue("id", kv.id_);
                sub_dict->SetValue("id", kv.id_);
                sub_dict->SetValue("title", kv.title_);
                sub_dict->SetValue("star", kv.star_);
            }
            //2.读磁盘当中预定义的html页面
            ctemplate::Template* tl =  ctemplate::Template::GetTemplate("./www/index.html", ctemplate::DO_NOT_STRIP);
            //3.渲染填充
            tl->Expand(html, &dict);
        }

        static void DrawoneQuestionHtml(const Question& ques, string* html){
            //1.组织ctemplate字典
            ctemplate::TemplateDictionary dict("question");
            dict.SetValue("id", ques.id_);
            dict.SetValue("title", ques.title_);
            dict.SetValue("star", ques.star_);
            dict.SetValue("desc", ques.desc_);
            dict.SetValue("id", ques.id_);
            dict.SetValue("code", ques.header_);

            //2.读磁盘当中预定义的html页面
            ctemplate::Template* tl =  ctemplate::Template::GetTemplate("./www/question.html", ctemplate::DO_NOT_STRIP);
            //3.渲染填充
            tl->Expand(html, &dict);
        }

        static void DrawCaseReaultHtml(Json::Value& resp_json, string* html){
            //1.组织ctemplate字典
            ctemplate::TemplateDictionary dict("case_reault");
            dict.SetValue("errno", resp_json["errorno"].asString());
            dict.SetValue("compile_result", resp_json["reason"].asString());
            dict.SetValue("case_result", resp_json["stdout"].asString());
            //2.读磁盘当中预定义的html页面
            ctemplate::Template* tl =  ctemplate::Template::GetTemplate("./template/case_result.html", ctemplate::DO_NOT_STRIP);
            //3.渲染填充
            tl->Expand(html, &dict);
        }
};
